﻿using System;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;

namespace TestCluster
{
    /// <summary>
    /// 
    /// </summary>
    [DependsOn(
        typeof(TestClusterDomainModule),
        typeof(AbpEntityFrameworkCoreModule)
    )]
    public class TestClusterEntityFrameworkCoreModule : AbpModule
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public override void ConfigureServices(ServiceConfigurationContext context)
        {

            Console.WriteLine($"{DateTime.Now} TestClusterEntityFrameworkCoreModule.ConfigureServices");
            var config = context.Services.GetConfiguration();
            Console.WriteLine($"==--- {config.GetSection("Redis:Prefix").Value} ---==");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public override void PreConfigureServices(ServiceConfigurationContext context)
        {
            Console.WriteLine($"{DateTime.Now} TestClusterEntityFrameworkCoreModule.PreConfigureServices");
            var config = context.Services.GetConfiguration();
            Console.WriteLine($"==--- {config.GetSection("Redis:Prefix").Value} ---==");

            System.AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
            //判断什么数据库类型
            context.Services.AddTransient<ITestClusterDbContext, TestClusterDbContext>();
            Configure<AbpDbContextOptions>(options => { options.UseNpgsql(); });
            context.Services.AddAbpDbContext<TestClusterDbContext>(options =>
            {
                options.AddDefaultRepositories<TestClusterDbContext>(includeAllEntities: true);
            });

            base.PreConfigureServices(context);
        }
    }
}